#define DEBUG damn skippy

#include <iostream>
#include <globals.h>

#ifdef _WINDOWS
#include <Windows.h>
#endif

#include "player.cpp"
#include "stats.cpp"
#include "inning.cpp"
#include "game.cpp"

using namespace std;

int main ( int argc, char ** argv ) {
	header(); // Online!
	player * p;
	std::vector<player *> * roster = new std::vector<player * >();
	try {
		do {
			p = new player(load_data());
			roster->push_back( p );
			output_dbug( "Added new player" );
		} while ( p->runStat("name") );
	} catch ( attr_error& ) {
		output_dbug( "Planned failure. Sorry, C++." );
		output_dbug( "OK. I've got all the players. Starting to process." );
	}
	clean_list( roster );
	output_dbug("");
	output_dbug(" == ROSTER == ");
	output_dbug("");
	for ( unsigned int i = 0; i < roster->size(); ++i ) {
		output_dbug( roster->at(i)->getStat("name")->getValue() );
	}
	output_dbug("");
	output_dbug(" == END ROSTER == ");
	output_dbug("");
	
	game * g = new game( roster );
	output_msg("Starting the game simulator");
	
#ifdef _WINDOWS
	if ( argc > 1 ) {
		output_dbug("Passed in a set seed");
		int time_seed = atoi(argv[1]);
		srand(time_seed);
	} else {
		output_dbug("Seeding with the time");
		srand(GetTickCount());
	}
#else
	if ( argc > 1 ) {
		output_dbug("Passed in a set seed");
		int time_seed = atoi(argv[1]);
		srand(time_seed);
	} else {
		output_dbug("Seeding with the time");
		srand(time(NULL));
	}
#endif

	g->run();

}
